package org.chen.common.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.chen.common.exception.ServiceException;

@Getter
@AllArgsConstructor
public enum VideoStatusEnum {
    PENDING(0, "待生成"),
    GENERATING(1, "生成中"),
    COMPLETED(2, "生成完成"),
    FAILED(3, "生成失败");
    
    private final Integer code;
    private final String desc;
    
    /**
     * 根据状态码获取描述
     */
    public static String getDesc(Integer code) {
        for (VideoStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status.getDesc();
            }
        }
        return "";
    }
    
    /**
     * 根据状态码获取枚举
     */
    public static VideoStatusEnum getByCode(Integer code) {
        for (VideoStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new ServiceException("未知的视频状态: " + code);
    }
    
    /**
     * 验证状态码是否有效
     */
    public static boolean isValid(Integer code) {
        for (VideoStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }
    
    /**
     * 判断是否为终态（完成或失败）
     */
    public static boolean isTerminal(Integer code) {
        return COMPLETED.getCode().equals(code) || FAILED.getCode().equals(code);
    }
    
    /**
     * 判断是否可以重试
     */
    public static boolean canRetry(Integer code) {
        return FAILED.getCode().equals(code);
    }
}